home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / tamsurum / tocom / Security Updates / SQL-MSDE-CriticalUpdate_ENU.msi / Hotfix3 / Files / qfe360814_dist.sql < prev    next >
Encoding:
Text File  |  2002-07-09  |  3.6 KB  |  118 lines

  1. IF EXISTS (select * from sysobjects where
  2.    name = 'sp_MSdeletefoldercontents' and type = 'P')
  3.       DROP PROCEDURE sp_MSdeletefoldercontents
  4.  
  5. raiserror(15339, -1, -1, 'sp_MSdeletefoldercontents')
  6. go
  7. --
  8. -- Name: sp_MSdeletefoldercontents
  9. --
  10. -- Description: This is a lighweight wrapper for deleting all files in the
  11. --              specified directory. This procedure is meant to be called by 
  12. --              a remote publisher for deleting files in the distributor's 
  13. --              context.
  14. --
  15. -- Parameter: @folder nvarchar(255) (mandatory)
  16. --
  17. -- Returns 0 - succeeded
  18. --         1 - failed
  19. --
  20. -- Security: Only members of the sysadmin server role and members of the 
  21. -- db_owner role of the distribution database can execute this function. This
  22. -- procedure is intended to be called through the distribution_admin remote 
  23. -- login from remote publishers
  24. --
  25. create procedure sp_MSdeletefoldercontents (
  26.     @folder nvarchar(255)
  27.     )
  28. as
  29. begin
  30.     set nocount on
  31.  
  32.     declare @command nvarchar(4000)
  33.     declare @retcode int
  34.  
  35.     select @retcode = 0
  36.     if len(@folder) = 0 or @folder is null
  37.     begin
  38.         return 0
  39.     end
  40.  
  41.     -- Append '\*' to the given path 
  42.     if substring(@folder, len(@folder), 1) <> N'\'
  43.     begin
  44.         select @folder = @folder + N'\'
  45.     end 
  46.  
  47.     select @folder = @folder + '*'    
  48.  
  49.     if (platform() & 0x1) = 0x1 
  50.     begin
  51.         select @command = 'del /q /f "' + fn_escapecmdshellsymbolsremovequotes(@folder) collate database_default + '"'
  52.     end
  53.     else
  54.     begin
  55.         -- Win9x 'del' command does not support the /q and /f switches
  56.         select @command = 'del "' + fn_escapecmdshellsymbolsremovequotes(@folder) collate database_default + '.*"'
  57.     end
  58.  
  59.     exec @retcode = master..xp_cmdshell @command, no_output
  60.     return @retcode
  61.  
  62. end
  63. go
  64.  
  65. IF EXISTS (select * from sysobjects where
  66.    name = 'sp_MSreplremoveuncdir' and type = 'P')
  67.       DROP PROCEDURE sp_MSreplremoveuncdir
  68. GO
  69.  
  70. CREATE PROCEDURE sp_MSreplremoveuncdir
  71. @dir nvarchar(260)
  72. as
  73.  
  74.     set nocount on
  75.  
  76.     declare @retcode int
  77.     declare @local_dir nvarchar(260)
  78.     declare @cmd nvarchar(1000)
  79.     declare @machinename sysname
  80.     /* 
  81.     ** We have to convert UNC to drive, otherwise will get 'Access denied' error in xp_cmdshell
  82.     */
  83.     select @machinename = convert(sysname, SERVERPROPERTY('machinename'))
  84.     EXEC @retcode = master.dbo.sp_MSunc_to_drive @unc_path = @dir, 
  85.         @local_server = @machinename, @local_path = @local_dir OUTPUT
  86.     IF @retcode <> 0 or @@ERROR <> 0 
  87.         RETURN(1)
  88.  
  89.     /*
  90.     ** Delete directory in the distributor's directory.
  91.     ** On Win9x, we have to use deltree instead
  92.     */
  93.     declare @platform_nt int 
  94.     select @platform_nt = 0x1
  95.     IF (( platform() & @platform_nt = @platform_nt))
  96.     BEGIN 
  97.         SELECT @cmd = 'if exist "' + fn_escapecmdshellsymbolsremovequotes(@local_dir) collate database_default + '" rmdir /S /Q ' + '"' + fn_escapecmdshellsymbolsremovequotes(@local_dir) collate database_default + '"'
  98.     END
  99.     ELSE
  100.     BEGIN
  101.         -- Don't need if exists check on Win9x but we do need 
  102.         -- to remove the trailing slash
  103.         IF SUBSTRING(@local_dir, LEN(@local_dir), 1) = N'\'
  104.         BEGIN
  105.             SELECT @local_dir = LEFT(@local_dir, LEN(@local_dir)-1)
  106.         END
  107.         SELECT @cmd = 'deltree /Y ' + '"' + fn_escapecmdshellsymbolsremovequotes(@local_dir) collate database_default + '"'
  108.     END
  109.  
  110.     EXECUTE  @retcode = master..xp_cmdshell @cmd, NO_OUTPUT
  111.     IF @retcode <> 0 or @@ERROR <> 0 
  112.     begin
  113.         raiserror(20015, 16, -1, @dir)
  114.         RETURN(1)
  115.     end
  116. go
  117.  
  118.